import { ref, nextTick, inject } from 'vue';
import { useRoute } from 'vue-router';
import { useKeepAliveStore } from '@/stores/modules/keepAlive';

const isRouterShow = ref(true);
export const usePageRefresh = () => {
  const route = useRoute();
  const keepAliveStore = useKeepAliveStore();

  const refreshCurrentPage = async () => {
    setTimeout(() => {
      keepAliveStore.removeKeepAliveName(route.name as string);
      isRouterShow.value = false;
      nextTick(() => {
        keepAliveStore.addKeepAliveName(route.name as string);
        isRouterShow.value = true;
      });
    }, 0);
  };

  return {
    isRouterShow,
    refreshCurrentPage
  };
};
